<?php
namespace Admin\Controller;

use Common\Controller\AdminbaseController;
class PeihuoController extends AdminbaseController{
	

	
	function _initialize() {
		parent::_initialize();
		$this->db = D("Peihuo");

	}
	
	function index(){


		$starttime = strtotime(I('get.starttime'));

		$endtime = strtotime(I('get.endtime'));


		if ($starttime || $endtime) {


			if (!$starttime) {
				$this->error("请填写开始时间");

			}


			if (!$starttime) {
				$this->error("请填写结束时间");
			}

			if ($starttime > $endtime) {
				$this->error("开始时间不能大于结束时间");


			}


			$map['inputtime'] = array('between', array($starttime, $endtime));

		}



		if(I("get.shuser")){

			$map['shuser']=I("get.shuser");

		}
		if(I("get.shop_id")){

			$map['shop_id']=I("get.shop_id");

		}





		$count=D("ViewsPeihuo")->where($map)->count();


		$page = $this->page($count, 10);



		$list=D("ViewsPeihuo")->where($map)->limit($page->firstRow . ',' . $page->listRows)->order ( "id desc")->select();
		$this->assign("Page",$page->show(""));


		$this->assign("list",$list);
		
		$this->display();
	}
	

	
	
	function add(){

		if(IS_POST){


			$ids = I("param.ids");


			$sps=D("Order")->where(array("id"=>array("in",$ids)))->group("shop_id")->getField("shop_id",true);


			foreach($sps as $k=>$v){

				$rds=D("Order")->where(array("id"=>array("in",$ids),"shop_id"=>$v))->getField("id",true);


				$data=array(
					"shop_id"=>$v,
					"order_list"=>implode(",",$rds),
				);

				if ($this->db->create($data)) {
					$this->db->add();
				}

			}


			$this->sucess("成功");


		}





	}

	

	
	
	}